<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
%>
	<script>
	function cardCountInit_check(selectObj,inputCount){
		 if(selectObj.val()==-1){
		 	alert("请选择计次项目");
		 	return false;
		 }
		 if(!inputCount){
		 	alert("请输入次数");
		 	return false;
		 }
		 var ex = /^\d+$/;
		if (!ex.test(inputCount)) {
			alert("只能输入整数");
			return false;
		} 
		return true;
	}
	
	function cardCountInit_deltr(obj){
		var productId=$(obj).parents("tr").attr("id");
		if(!confirm("您确定要删除该计次项目吗？"))return;
		$.ajax({cache:false, 
		url:"<%=path%>/ajax/deleteCardCountInit.do?cardEntityId=${cardCountInitVO.cardEntityId}&productId="+productId, 
		type:"post", 
		dataType:"json", 
		success:handProcessResult});
	}
	
	function handProcessResult(json){
		DWZ.ajaxDone(json);
		if (json.statusCode == DWZ.statusCode.ok){
			reloadPage();
		}
	}

	function cardCountInit_ajaxsubmit(){
		var productId=$("select[name='cardCountInitVO.productVO.id']").val();
		var selectObj = $("select[name='cardCountInitVO.productVO.id']").find("option:selected");
		var inputCount = $("input[name='cardCountInitVO.count']").val();
		if(cardCountInit_check(selectObj,inputCount)){
			$.ajax({cache:false, url:"<%=path%>/ajax/saveCardCountInit.do?cardEntityId=${cardCountInitVO.cardEntityId}&productId="+productId+"&inputCount="+inputCount, type:"post", dataType:"json", success:handProcessResult});
		}
	}
	
	function reloadPage(){
		return divSearch($("#cardCountInit_form"), "cardEntityEdit_cardCountInit");
	}
</script>
<div id="cardEntityEdit_cardCountInit">
	<form id="pagerForm" method="post" action="<%=path%>/cardCountInit/listCardCountInit.action?customerId=${customerId}&cardEntityId=${cardCountInitVO.cardEntityId}">
		<input type="hidden" name="pageRequest" value="1" />
		<input type="hidden" name="pageNum" value="${paginator.pageIndex}" />
		<input type="hidden" name="numPerPage" value="${paginator.pageSize}" />
	</form>
		<div class="pageContent">
		<c:choose>
		<c:when test="${cardCountInitVO.cardEntityId!=null && cardCountInitVO.cardEntityId!=''}">
			<form method="post" action="<%=path%>/cardCountInit/saveCardCountInit.action" class="pageForm required-validate">
				<div class="pageFormContent">
					<input type="hidden" name="cardCountInitVO.cardEntityId" value="<s:property value="cardCountInitVO.cardEntityId"/>"/>
					<p>
						<label>
							计次项目：
						</label>
						<select name="cardCountInitVO.productVO.id" >
							<option value="-1">请选择</option>
							<s:iterator value="productList" id="product" status="st">
								<option value="<s:property value="id" />"${cardCountInitVO.productVO.id==product.id?" selected":""}><s:property value="name" /></option>
							</s:iterator>
	              		</select>
					</p>
					<p>
						<label>
							次 数：
						</label>
						<input name="cardCountInitVO.count"
							value="<s:property value="cardCountInitVO.count" />"
							class="required digits" type="text" size="30"/>
					</p>
				</div>
				<div class="formBar">
					<ul>
						<li>
							<div class="buttonActive">
								<div class="buttonContent">
									<button type="button" onclick="cardCountInit_ajaxsubmit();">
										增加
									</button>
								</div>
							</div>
						</li>
					</ul>
				</div>
				<table class="table" width="100%" layoutH="170">
					<thead>
						<tr>
							<th width="50%">
								计次项目
							</th>
							<th width="30%">
								次 数
							</th>
							<th width="70">
								操作
							</th>
						</tr>
					</thead>
					<tbody id="tab">
						<s:iterator value="cardCountInitList" id="cardCount" status="st">
							<tr class="" id="<s:property value="productVO.id" />">
								<td>
									<s:property value="productVO.name" />
								</td>
								<td>
									<s:property value="count" />
								</td>
								<td>
									<a class="btnDel" onclick="cardCountInit_deltr(this);">删除</a>
								</td>
							</tr>
						</s:iterator>
					</tbody>
				</table>
			</form>
			<div class="panelBar">
		<div class="pages">
				<span>显示</span>
				<select class="combox" name="numPerPage" onchange="navTabPageBreak({numPerPage:this.value},'cardEntityEdit_cardCountInit')">
					<option value="15" <c:if test="${paginator.pageSize==15}">selected='selected'</c:if> >15</option>
					<option value="30" <c:if test="${paginator.pageSize==30}">selected='selected'</c:if> >30</option>
					<option value="50" <c:if test="${paginator.pageSize==50}">selected='selected'</c:if> >50</option>
					<option value="100" <c:if test="${paginator.pageSize==100}">selected='selected'</c:if> >100</option>
					<option value="200" <c:if test="${paginator.pageSize==200}">selected='selected'</c:if> >200</option>
				</select>
				<span>条，共${paginator.totalCount}条</span>
			</div>
			<div class="pagination" rel="cardEntityEdit_cardCountInit" totalCount="${paginator.totalCount}" 
				numPerPage="${paginator.pageSize}" pageNumShown="10" currentPage="${paginator.pageIndex}"></div>

	</div>
		</c:when>
			<c:otherwise>
				<p><span style="color:red">请先创建会员卡</span></p>
			</c:otherwise>
		</c:choose>
		</div>
		<div>
		<form id="cardCountInit_form" method="post" rel="pagerForm" action="<%=path%>/cardCountInit/listCardCountInit.action?customerId=${customerId}&cardEntityId=${cardCountInitVO.cardEntityId}" onsubmit="return reloadPage(this);"></form>
		</div>
</div>